import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { asyncScheduler } from 'rxjs';
import { Router } from '@angular/router';

import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")


const today = new Date();
const month = today.getMonth();
const year = today.getFullYear();



@Component({
  selector: 'app-page-home,',
  templateUrl: './page-home.component.html',
  styleUrls: ['./page-home.component.css']
})

export class PageHomeComponent implements OnInit {
  constructor(private router: Router) {
  }
  async ngOnInit(): Promise<void> {
    this.getSwtUser();
    let work = await this.getSwtWork();
    this.workList = this.workList.concat(work);
    let query = new Parse.Query("swt_work");
    let slist = await query.find();
    await this.getRoom();
    await this.getPolicy();
  }

  // async getPolicyByName(){

  // }
  getDetail() {
    this.router.navigate(["/mobile-school/active-detail"], {
    })
  }
  RentingList: any = []
  policyList:any=[]
  async getRoom() {
    let query = new Parse.Query("renting")
    this.RentingList = await query.find()
  }
  async getPolicy(){
    let query = new Parse.Query("swt_policy")
    this.policyList = await query.find()
  }
  async getSwtUser() {
    let result = await fetch("http://metapunk.cn:9999/parse/classes/swt_user?where={%22user_name%22:%22%E4%B8%A5%E6%99%94%E5%9E%9A%22}", {
      "headers": {
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "pragma": "no-cache",
        "x-parse-application-id": "dev"
      },
      "referrer": "http://localhost:4040/",
      "referrerPolicy": "strict-origin-when-cross-origin",
      "body": null,
      "method": "GET",
      "mode": "cors",
      "credentials": "omit"
    });
    let data = await result.json();
    console.log(data);

  }
  async getSwtWork() {
    let result = await fetch("http://metapunk.cn:9999/parse/classes/swt_work?", {
      "headers": {
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "pragma": "no-cache",
        "x-parse-application-id": "dev"
      },
      "referrer": "http://localhost:4040/",
      "referrerPolicy": "strict-origin-when-cross-origin",
      "body": null,
      "method": "GET",
      "mode": "cors",
      "credentials": "omit"
    });
    let data = await result.json();
    console.log(data);
    return data?.results;
  }

  campaignOne = new FormGroup({
    start: new FormControl(new Date(year, month, 13)),
    end: new FormControl(new Date(year, month, 16)),
  });
  campaignTwo = new FormGroup({
    start: new FormControl(new Date(year, month, 15)),
    end: new FormControl(new Date(year, month, 19)),
  });
  workList = [
    { companyName: "阿里巴巴", job: "C++程序员", companyTelephone: "17607948748", pay: "6000", number: "20-99人", location: "杭州市 余杭区", exp: "经验不限", recruiter: "苏先生高级后端工程师" },
    { companyName: "腾讯", job: "Java后端开发", companyTelephone: "17612345678", pay: "5000", number: "20-99人", location: "深圳市 龙华区", exp: "1-3年", recruiter: "赵先生人事专员" }
  ]

  houseList = [
    { title: "房源1", type: "整租", contact: "13812345678", price: "2500", rooms: "1室1厅", location: "北京市 朝阳区", experience: "一年起租", agent: "李先生房产经纪人" },
    { title: "房源2", type: "合租", contact: "13998765432", price: "1800", rooms: "3室2厅", location: "上海市 浦东新区", experience: "支持短租", agen: "王小姐房屋中介" },
    { title: "房源3", type: "整租", contact: "13655556666", price: "3200", rooms: "2室1厅", location: "广州市 天河区", experience: "半年起租", agent: "张先生房产经纪人" },
  ]
}


